/*
  File: Time.cpp
  RCD A.2
*/
#include"Time.h"
using namespace std;

Time::Time(int hh, int mm) : h(hh), m(mm) {
  if(!is_time(hh, mm))
    throw Invalid();
}

Time::Time() : h(0), m(0) {
}

/* doesn't take Date into account when hour overflows
void Time::add_hour(int n) {
  while(n > 0) {
    h++;
    if(h > 23)
      h = 0;
    n--;
  }
}

void Time::add_minute(int n) {
  while(n > 0) {
    m++;
    if(m > 59) {
      m = 0;
      h++;
      if(h > 23)
	h = 0;
    }
    n--;
  }
}
*/

bool is_time(int h, int m) {
  if(h >= 0 && h <= 23 && m >= 0 && m <= 59)
    return true;
  else
    return false;
}

bool operator==(const Time& a, const Time& b) {
  if(a.hour() == b.hour() && a.minute() == b.minute())
    return true;
  else
    return false;
}

bool operator!=(const Time& a, const Time& b) {
  if(a.hour() == b.hour() && a.minute() == b.minute())
    return false;
  else
    return true;
}

std::ostream& operator<<(ostream& os, const Time& t) {
  return os << t.hour() << ' ' << t.minute();
}

std::istream& operator>>(istream& is, Time& tt) {
  int h, m;
  is >> h >> m;
  if(!is)
    return is;
  tt = Time(h, m);
  return is;
}
